<template>
	<view>
		<view class="box" v-for="(item, index) in list" :key="index">
			<view class="tilte">{{item.name}}</view>
			<view class="cardList">
				<view class="card" v-for="(obj, iii) in item.arr" :key="iii" @click="skipPageFun(obj)">
					<image v-if="obj.img" :src="obj.img" mode="aspectFill"></image>
					<u-icon v-else :name="obj.icon" color="#007aff" size="68" class="iconClass"></u-icon>
					<view>{{obj.name}}</view>
				</view>
			</view>
		</view>
		<!--无网络提示-->
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{
						name: '应用管理',
						arr: [
							{ name: '客户管理', icon: '../../static/crm/threadChi.png', url: '../pages/crm/index', menu_id: 'CstClue/show_public' },
							{ name: '客户', img: '../../static/crm/kehu1.png', url: '/kehu/kehu', menu_id: 'client' },
							{ name: '联系人', img: '../../static/crm/lianxiren.png', url: './lianxiren/lianxiren', menu_id: 'linkman' },
							// { name: '附近的客户', img: '../../static/crm/fujinkehu.png', url: './fujin/fujin', menu_id: 'nearby' },
							// { name: '查重工具', img: '../../static/crm/chachong.png', url: './chaChong/chaChong', },
							{ name: '跟进记录', img: '../../static/crm/genjin.png', url: './genJin/genJin', menu_id: 'followUp' }
						]
					},
					{
						name: '产品管理',
						arr: [
							{ name: '商城预览', img: '../../static/crm/shopIcon.png', url: '../../chanpin/view/shop' },
							{ name: '产品管理', img: '../../static/crm/chanpin.png', url: '../../chanpin/view/chanpin', menu_id: 'pList' },
							{ name: '产品分类', img: '../../static/crm/cpfl.png', url: '../../chanpin/view/classify', menu_id: 'pClassify' }
						]
					},
				]
			}
		},
		onShow() {
			if(uni.$isLoginFun()) {
				//this.getBacklogFun();
			}
		},
		methods: {
			skipPageFun: function (obj) {
				console.log('skipPageFun:');
				let url = obj.url;
				console.log(url);
				if(uni.$isLoginFun()) {
					let isHave = true;
					uni.navigateTo({
						url
					})
					if(isHave) {
						uni.navigateTo({
							url
						})
					} else {
						uni.showModal({
							title: '提示',
							content: '暂无权限！',
							showCancel: false
						})
					}
				}
			},
			// 获取待办数据
			getBacklogFun: function() {
				let that = this;
				let user = uni.$userInfo || null;
				let obj = {}
				if(user.isDepManager == 1) {
					obj.depId = user.depId;
				} else {
					obj.fuZeRenId = user._id;
				}
				let dArr = getDayFun();
				let dArr1 = getDayByNumFun(-7);
				let dArr2 = getDayByNumFun(-30);
				let reqData = {
					action: 'getBacklogNum',
					params: {
						fuZeRenId: obj.fuZeRenId,
						depId: obj.depId,
						sTime: dArr[0],
						eTime: dArr[1],
						sTime1: dArr1[1],
						eTime1: dArr1[0],
						sTime2: dArr2[1],
						eTime2: dArr2[0]
					}
				}
				baobiaoApi(reqData)
					.then(res => {
						let obj = res.result;
						let total = obj.thread + obj.client + obj.contact + obj.business + obj.quotation + obj.contract+ obj.hkjh
							+ obj.hkd + obj.daoqiContract + obj.hkTixing;
						if(total > 0) {
							if(total > 99) {
								total = '99+'
							}
							uni.setTabBarBadge({
								index: 1,
								text: total + ''
							})
						} else {
							uni.hideTabBarRedDot({
								index: 1
							})
						}
					})
			},
		}
	}
</script>
<style>
	page {
		padding-bottom: 100rpx;
	}
	.box {
		box-sizing: border-box;
		border-radius: 16rpx;
		width: 686rpx;
		margin: 32rpx;
		padding: 26rpx;
		box-shadow: #dddddd 0px 0px 32rpx;
	}

	.tilte {
		font-size: 32rpx;
		font-weight: bold;
	}

	.cardList {
		margin-top: 26rpx;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.card {
		font-size: 28rpx;
		width: 159rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 32rpx;
	}

	.card>image {
		width: 68rpx;
		height: 68rpx;
		margin-bottom: 6rpx;
	}
	.iconClass {
		margin-bottom: 6rpx;
	}
</style>
